package com.example.redisDemo.test;

public class NextDay {
    public Date nextday(Date d) {
        int month = d.getMonth();
        int day = d.getDay();
        int year = d.getYear();
        Date next;
        switch (month) {
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
                if (day == 31) {
                    month = month + 1;
                    day = 1;
                } else {
                    day = day + 1;
                }
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                if (day == 30) {
                    month = month + 1;
                    day = 1;
                } else {
                    day = day + 1;
                }
                break;
            case 12:
                if (day == 31) {
                    month = 1;
                    day = 1;
                    year = year + 1;
                } else {
                    day = day + 1;
                }
                break;
            case 2:
                if (isleap(year)) {
                    if (day == 29) {
                        day = 1;
                        month = 3;
                    } else {
                        day = day + 1;
                    }
                } else {
                    if (day == 28) {
                        day = 1;
                        month = 3;
                    } else {
                        day = day + 1;
                    }
                }
                break;
        }
        next = new Date(month, day, year);
        return next;
    }

    public boolean isleap(int year) {
        if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
            return true;
        else {
            return false;
        }
    }
}
